package com.packet.cheng;
/**
 @author zaicheng
 @version 1.0
 @date 2022-04-19
 @email zzc15847256473@163.com
 */

import redis.clients.jedis.*;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class JedisClusterTest {

    public static void main(String[] args) throws IOException {
        JedisPoolConfig jedisPoolConfig  = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(20);
        jedisPoolConfig.setMaxIdle(10);
        jedisPoolConfig.setMinIdle(5);

        String masterName = "mymaster";
        Set<HostAndPort> jedisClusterNodes = new HashSet<>();
        jedisClusterNodes.add(new HostAndPort("192.168.88.66",8001));
        jedisClusterNodes.add(new HostAndPort("192.168.88.67",8002));
        jedisClusterNodes.add(new HostAndPort("192.168.88.68",8003));
        jedisClusterNodes.add(new HostAndPort("192.168.88.66",8004));
        jedisClusterNodes.add(new HostAndPort("192.168.88.67",8006));
        jedisClusterNodes.add(new HostAndPort("192.168.88.68",8008));

        JedisCluster jedisCluster = null;


        try {
            // connectionTimeOut:指的是连接一个url的连接等待时间
            // soTimeout: 指的是连接上一个url,获取response的返回等待时间
            jedisCluster = new JedisCluster(jedisClusterNodes,6000,5000,10,jedisPoolConfig);

            System.out.println(jedisCluster.set("cluster","zaicheng"));

            System.out.println(jedisCluster.get("sentinel"));

        }catch (Exception  e){
            e.printStackTrace();
        }finally {

            if (jedisCluster != null){
                jedisCluster.close();
            }
        }
    }


}
